package com.core.website.service.impl;

import com.core.website.entity.Banner;
import com.core.website.mapper.BannerMapper;
import com.core.website.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.naming.Name;
import java.util.List;
import java.util.UUID;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    @Override
    @CacheEvict(value="banner",allEntries = true)
    public int add(Banner banner) {
        banner.setId(UUID.randomUUID().toString().toUpperCase().replace("-", ""));
        if(banner.getStatus()==null){
            banner.setStatus(1);//默认值是1 可用
        }
        return bannerMapper.add(banner);
    }

    @Override
    @CacheEvict(value="banner",allEntries = true)
    public int edit(Banner banner) {
        return bannerMapper.edit(banner);
    }

    @Override
    @CacheEvict(value="banner",allEntries = true)
    public int delete(List<String> ids) {
        return bannerMapper.delete(ids);
    }

    @Override
    @Cacheable(value = "banner",keyGenerator = "selfKeyGenerate")
    public List<Banner> queryAll(Banner banner) {
        List<Banner> result=bannerMapper.queryAll(banner);
        return result;
    }

    @Override
    @Cacheable(value = "banner",key = "#id")
    public Banner queryOne(String id) {
        Banner banner=bannerMapper.queryById(id);
        return banner;
    }
}
